<?php
namespace app\api\controller;
use think\Request;
use app\api\controller\Base;
use app\api\model\UserOrder as MuserOrder;

/**
 * @title order 订单接口|[客户端]
 * @description 与订单有关的信息
 */
 
class UserOrder extends Base
{
    /**
     * @title order/list 查询订单列表信息 GET
     * @description 说明：依据 user_id 订单列表信息 
     * @author 虾哥@2424899422@qq.com
     * @url order/list/
	 * @Turl api/user_order/lists
	 
	 * @param name:user_id type:int require:1 default:null other: desc:用户ID
	 * @param name:page type:int require:0 default:1 other: desc:当前页ID
	 * @param name:length type:int require:0 default:5 other: desc:当前页显示数量
	 *
     */
    public function lists($user_id,$page,$length)
    {
		$return = array('code' => 0, 'message' => 'query order list success !', 'data' => array());
		$data = MuserOrder::lists($user_id,$page,$length);
		if (empty($data)) {
            $return['code'] = 1;
            $return['message'] = 'query order list failed !';
            return $return;
        }
        $return['data'] = $data;
		return json($return);	
    }
	
	
	/**
     * @title order/create 添加商品到订单 POST
     * @description 说明：依据 user_id 添加商品到订单 |【暂不支持批量添加】
	 * @author 虾哥@2424899422@qq.com
	 * @url order/create/
	 * @Turl api/user_order/create
	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为新增行数
     * 
     */
    public function create() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'create order success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MuserOrder::cartAdd($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'create order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
	}
	
	
	/**
     * @title order/order_confirm 订单确认 POST
     * @description 依据 order_id 订单确认 
	 * @author 虾哥@2424899422@qq.com
	 * @url order/order_pay/
	 * @Turl api/user_order/order_pay

	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为更新行数
     */

    public function order_confirm() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'update order success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MuserOrder::cartUpdate($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'update order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	 
    }
	
	/**
     * @title order/delete 删除订单 GET
     * @description 依据 address_ids 删除订单 | 【暂不支持批量删除】| 支持清空购物车
	 * @author 虾哥@2424899422@qq.com
	 * @url order/delete/
	 * @Turl api/user_order/delete
	
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为删除行数
     *
     */
	 
    public function delete($order_id,$user_id,$is_all_clear) {
        $return = array('code' => 0, 'message' => 'delete order success !', 'data' => array());
		$data = MuserOrder::cartDelete($order_id,$user_id,$is_all_clear);
		if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'delete order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
    }
	
	/**
     * @title order/cancel 取消订单 GET
     * @description 依据 address_ids 删除订单 | 【暂不支持批量删除】| 支持清空购物车
	 * @author 虾哥@2424899422@qq.com
	 * @url order/cancel/
	 * @Turl api/user_order/cancel

	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为删除行数
     *
     */
    public function cancel($order_id,$user_id,$is_all_clear) {
        $return = array('code' => 0, 'message' => 'delete order success !', 'data' => array());
		$data = MuserOrder::cartDelete($order_id,$user_id,$is_all_clear);
		if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'delete order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
    }
	
	/**
     * @title order/order_pay 订单支付 POST
     * @description 依据 order_id 订单支付 
	 * @author 虾哥@2424899422@qq.com
	 * @url order/order_pay/
	 * @Turl api/user_order/order_pay
	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为更新行数
     */

    public function order_pay() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'update order success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MuserOrder::cartUpdate($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'update order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	 
    }

	/**
     * @title order/update 订单支付 POST
     * @description 依据 order_id 订单支付 
	 * @author 虾哥@2424899422@qq.com
	 * @url order/order_pay/
	 * @Turl api/user_order/order_pay
	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为更新行数
     */

    public function update() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'update order success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MuserOrder::cartUpdate($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'update order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	 
    }


	/**
	支付方式	pay_id	是	Int	5	支付方式	1.3.0	
	运输方式	shipping_id		Int	3	运输方式	1.3.0	
	购物车id	rec_id	Int	是	4	购物车id	1.3.0	
	收货地址id	address_id	Int	是	0	默认为0，0为默认地址	1.3.0	
	积分	integral	Int	是		积分	1.3.0	
	发票类型	inv_type	string	是		发票类型	1.3.0	
	发票抬头	inv_payee	string	是		发票抬头	1.3.0	
	发票内容	inv_content	string	是		发票内容	1.3.0	
	发票纳税人识别码	inv_tax_no	string	是	门店和小程序时新增	发票纳税人识别码	1.7.0	
	发票抬头类型	inv_title_type
	
	
	
    public function done() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'update order success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MuserOrder::cartUpdate($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'update order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	 
    }
	*/

}
